# Contributor: Alex McGrath <amk@amk.ie>
# Maintainer: Alex McGrath <amk@amk.ie>
pkgname=ntfy
pkgver=2.11.0
pkgrel=4
pkgdesc="A simple HTTP-based pub-sub notification service"
url="https://ntfy.sh/"
# riscv64: fails to build
arch="all !riscv64"
license="GPL-2.0-only AND Apache-2.0"
subpackages="$pkgname-openrc"
makedepends="go nodejs npm mkdocs mkdocs-material sqlite-dev"
install="$pkgname.pre-install"
source="$pkgname-$pkgver.tar.gz::https://github.com/binwiederhier/ntfy/archive/refs/tags/v$pkgver.tar.gz
	ntfy.initd
	ntfy.confd
	"
# random network errors
options="net !check"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

prepare() {
	default_prepare

	sed -i 's/^# listen-http: ":80"/listen-http: ":8080"/g' server/server.yml
}

build() {
	make web
	mkdir -p dist/ntfy_linux_server server/docs
	touch server/docs/index.html server/site/app.html
	CGO_ENABLED=1 go build \
		-o dist/ntfy_linux_server/ntfy \
		-tags sqlite_omit_load_extension,osusergo,netgo,libsqlite3 \
		-ldflags \
		"-linkmode=external -extldflags '$LDFLAGS' -X main.version=$pkgver -X main.commit=release -X main.date=alpine-package"

}

check() {
	make test
}

package() {
	install -m755 -D "$srcdir"/$pkgname.initd \
		"$pkgdir"/etc/init.d/$pkgname
	install -m644 -D "$srcdir"/$pkgname.confd \
		"$pkgdir"/etc/conf.d/$pkgname
	install -Dm755 "$builddir"/dist/"$pkgname"_linux_server/"$pkgname" \
		"$pkgdir"/usr/bin/"$pkgname"
	install -Dm644 "$builddir"/client/client.yml \
		"$pkgdir"/etc/ntfy/client.yml
	install -Dm644 "$builddir"/server/server.yml \
		"$pkgdir"/etc/ntfy/server.yml
}

sha512sums="
9c665125197742be86230ef6bf7131f69041c584ce4650d1b9b4b546abd04911eee4a3f4d905783de352bc185bfbf36d20f2e77efac6147cf6bc62953ad785e2  ntfy-2.11.0.tar.gz
5de3242dded5b9f47ee23063ba43e02f5ffc7cd17cee6953c0bb24609d7030a2a2dd7c386f07416e6dbe68698232c7096ff9407f7d3ebedc00a7207f6796f7d9  ntfy.initd
0e016b9f62ba3b0c555757abeb8152e7fb77825ff6451bda820173750fa3ddd449fbc1330ddd7d77db98cff39dc6ab897bc046004469688bf7289be8049890a9  ntfy.confd
"
